package eureka.consumer.config;

import eureka.consumer.controller.EurekaConsumerController;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author RenPu
 * @Date 2021/7/7 12:28
 * @Version 1.0
 * @Description:设置扑获全局异常，进行颗粒化精细到具体的异常
 **/
@RestControllerAdvice
@ResponseBody
public class GolableExceptionHandle {

    @ExceptionHandler(value = ArithmeticException.class)
    @ResponseBody
    public Map errorHandler(HttpServletRequest req, ArithmeticException ex) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("message", ex.getMessage());
        return map;
    }

    @ExceptionHandler(value = NullPointerException.class)
    @ResponseBody
    public Map errorHandlerTwo(HttpServletRequest req, NullPointerException ex) {
        Map map = new HashMap();
        map.put("code", 407);
        map.put("message", ex.getMessage());
        return map;
    }

}
